package com.zc.basic.infra.mybatis.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.zc.basic.domain.pojo.gis.GeoPoint;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AutoSqlInjector extends AbstractSqlInjector {

    private final DefaultSqlInjector injector = new DefaultSqlInjector();

    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {

        List<AbstractMethod> methodList = injector.getMethodList(mapperClass, tableInfo);

        for (TableFieldInfo fieldInfo : tableInfo.getFieldList()) {
            Class<?> propertyType = fieldInfo.getPropertyType();
            if (propertyType.equals(GeoPoint.class)) {
                methodList.add(new SaveEntity());
            }
        }

        return methodList;
    }
}
